package com.briup.estore.adminAPI.web.controller;

import com.briup.estore.common.bean.Admin;
import com.briup.estore.common.service.IAdminService;
import com.briup.estore.common.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author adam
 * @date 2022/8/15
 */
@Api(tags = "管理员信息相关接口")
@RestController
@RequestMapping("admin")
@CrossOrigin
@Slf4j
public class AdminController {
    @Autowired
    private IAdminService service;

    @ApiOperation("管理员登录")
    @PostMapping("login")
    public Result login(@RequestBody Admin admin) {
        Map<String, String> map = service.login(admin.getUsername(), admin.getPassword());
        return Result.success(map);
    }

    @ApiOperation("管理员退出登录")
    @PostMapping("loginOut")
    public Result loginOut(@RequestBody  String userName) {
        log.info("准备退出");
        service.loginOut(userName);
        log.info("退出登录");
        return Result.success();

    }

    @ApiOperation("添加新的管理员")
    @PostMapping("register")
    public Result register(@RequestBody Admin admin) {
            service.register(admin);
            return Result.success();
    }


}
